#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>

#define f(x, l, r) for (int x = l; x <= r; ++ x)
#define get_sum(x1, y1, x2, y2) s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1]

using namespace std;

const int N = 20, M = 10;

int n, m = 8;
int s[M][M];
double f[M][M][M][M][N];
double X;

double get(int x1, int y1, int x2, int y2) {
    double sum = get_sum(x1, y1, x2, y2) - X;
    return (double)sum * sum / n;
}

double dp(int x1, int y1, int x2, int y2, int k) {
    double &v = f[x1][y1][x2][y2][k];
    if (v >= 0) return v;
    if (k == 1) return v = get(x1, y1, x2, y2);
    
    v = 1e9;
    f(i, x1, x2 - 1) {
        v = min(v, get(x1, y1, i, y2) + dp(i + 1, y1, x2, y2, k - 1));
        v = min(v, get(i + 1, y1, x2, y2) + dp(x1, y1, i, y2, k - 1));
    }
    
    f(i, y1, y2 - 1) {
        v = min(v, get(x1, y1, x2, i) + dp(x1, i + 1, x2, y2, k - 1));
        v = min(v, get(x1, i + 1, x2, y2) + dp(x1, y1, x2, i, k - 1));
    }
    return v;
}

int main() {
    cin >> n;
    
    f(i, 1, m) f(j, 1, m) {
        cin >> s[i][j];
        s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
    }
    
    X = (double)s[m][m] / n;
    memset(f, -1, sizeof f);
    
    printf("%.3lf", sqrt(dp(1, 1, 8, 8, n)));
    
    return 0;
}